// pages/joinUs/joinUs.js
var call = require("../../utils/request.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    conditionBox:[
      {
        conditiontext: "必须是小区业主，或者在小区周边有门店。",
      },
      {
        conditiontext: "加盟费和保证金XXXX元.",
      },
      {
        conditiontext:"申请小区有收货点。",
      },
      {
        conditiontext: "每天能有稳定时间服务社区用户。",
      },
      {
        conditiontext: "目前全国小区均可申请入驻！",
      }
    ],

    applicantName: '',//申请人姓名
    mobilephoneNumber: '',//手机号码
    addressPro:'',//省份
    addressCity:'',//城市
    villageName:'',//小区名称
    addressNumber:'',//门牌号
    openingBank:'',//开户行
    bankCard:'',//银行卡号
    
    detailPro:'请选择省份',
    detail:'请选择城市',
    detailed: '请选择所在区域',
    detailBank:'请选择银行名称',
    // region: [],
    // customItem: ["全部"],
    // clas: 'ccc',



    // arrayPro:['江苏','北京','上海'],//省份
    arrayPro:[
      {
        id: 0,
        name: '美国'
      },
      {
        id: 1,
        name: '中国'
      },
      {
        id: 2,
        name: '巴西'
      },
      {
        id: 3,
        name: '日本'
      }
    ],
    //arrayCity:['苏州','南京','无锡'],//城市
    arrayCity: [{
      id: 0,
      name: '苏州'
    },
      {
        id: 1,
        name: '南京'
      },
      {
        id: 2,
        name: '无锡'
      }],
    array: ['吴中区', '姑苏区', '高新区', '吴江区'],//所在区域地址
    arrayBank:['中国建设银行','中国工商银行','中国邮政'],

    viewShowPro:"block",
    viewShowCity: "block",
    viewShow:"block",
    viewShowBank:"block",

    proId: '1',//省id

  },


  //申请人姓名
  applicantName:function(e){
    var that = this;
    that.setData({
      applicantName: e.detail.value
    })
    //console.log(e.detail.value)
    var proposerName = that.data.applicantName;
    if (proposerName == "") {
      wx.showToast({
        title: '请填写申请人姓名',
        duration: 2000,
        icon: "none"
      })
    }
  },

  //手机号码
  mobilephoneNumber:function(e){
    var that = this;
    that.setData({
      mobilephoneNumber: e.detail.value
    })
   // console.log(e.detail.value)
    var proposerNumber = that.data.mobilephoneNumber;
    var theNumberlength = proposerNumber.length
    if (proposerNumber == "") {
      wx.showToast({
        title: '请输入手机号',
        duration: 2000,
        icon: "none"
      })
    }else if (theNumberlength != 11) {
      wx.showToast({
        title: '手机号错误',
        duration: 2000,
        icon: "none"
      })
    }
  },

//地址
  //省份
  bindPickerChangePro(e) {
    var that = this
    //console.log(this.data.arrayPro[e.detail.value])
    // console.log(this.data.arrayPro[e.detail.value].id)
    var thename = this.data.arrayPro[e.detail.value].name
    var theId = this.data.arrayPro[e.detail.value].id
    //console.log('picker发送选择改变，携带值为', e.detail.value)
    //console.log(theId)
    that.setData({
      IndexPro: e.detail.value,
      viewShowPro: "none",
      province: thename,
      proId:theId,
      thename: thename,
    })
    console.log("获取省id")
    console.log(that.data.proId)
    var parms = {
      provinceID: that.data.proId
    }
    call.getData('address/getCityList', parms, this.cityList, this.fail); //获取市列表
  },
  //城市
  bindPickerChangeCity(e){
    var that = this
    var thecity = this.data.arrayCity[e.detail.value].name
    var thecityId = this.data.arrayCity[e.detail.value].id
    //console.log('picker发送选择改变，携带值为', e.detail.value)
    that.setData({
      Index: e.detail.value,
      viewShowCity: "none",
      city:thecity,
      thecity: thecity,
      cityId:thecityId,
    })
    console.log(that.data.thecity)
    console.log(that.data.cityId)
    var params = {
      cityID:that.data.cityId
    }
    call.getData('address/getCountyList', params, this.areaList, this.fail); //获取区列表
  },
  //所在区域
  bindPickerChange(e) {
    var thearea = this.data.array[e.detail.value].name
    var theareaId = this.data.array[e.detail.value].id
    //console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index: e.detail.value,
      viewShow:"none",
      area:thearea,
      theArea: thearea,
      areaId: theareaId,
    })
    console.log(this.data.theArea)
    console.log(this.data.areaId)
  },

  //小区名称
  villageName:function(e){
    var that = this;
    that.setData({
      villageName: e.detail.value
    })
    //console.log(e.detail.value)
    var proposervillage = that.data.villageName;
    if (proposervillage == "") {
      wx.showToast({
        title: '请填写小区名称',
        duration: 2000,
        icon: "none"
      })
    }
  },

  //地址门牌号
  addressNumber: function (e) {
    var that = this;
    that.setData({
      addressNumber: e.detail.value
    })
    //console.log(e.detail.value)
    var proposervaddressNumber = that.data.addressNumber;
    if (proposervaddressNumber == "") {
      wx.showToast({
        title: '请填写门牌号',
        duration: 2000,
        icon: "none"
      })
    }
  },


  //银行
  bindPickerChangeBank(e) {
    var thebank = this.data.arrayBank[e.detail.value]
    //console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      IndexBank: e.detail.value,
      viewShowBank: "none",
      bank: thebank,
    })
  },

  //开户行
  openingBank:function(e){
    var that = this;
    that.setData({
      openingBank:e.detail.value
    })
    //console.log(e.detail.value)
    var openbank = that.data.openingBank;
    if(openbank ==""){
      wx.showToast({
        title: '开户行不得为空',
        duration:2000,
        icon:"none"
      })
    }
  },

  //银行卡号
  bankCard: function (e) {
    var that = this;
    that.setData({
      bankCard: e.detail.value
    })
    //console.log(e.detail.value)
    var bankcard = that.data.bankCard;
    if(bankcard ==""){
      wx.showToast({
        title: '银行卡号不得为空',
        duration:2000,
        icon:"none"
      })
    }
  },

  // //选择地区
  // bindRegionChange: function (e) {
  //   var that = this
  //   //为了让选择框有个默认值，    
  //   that.setData({
  //     clas: ''
  //   })　　　//下拉框所选择的值
  //   console.log('picker发送选择改变，携带值为', e.detail.value)

  //   this.setData({
  //     //拼的字符串传后台
  //     detailed: e.detail.value[0] + "," + e.detail.value[1] + "," + e.detail.value[2],
  //     //下拉框选中的值
  //     region: e.detail.value
  //   })
  // },

   //上传
  upLoad:function(e){
    wx.chooseImage({
      success(res) {
        const tempFilePaths = res.tempFilePaths
        // wx.uploadFile({
        //   url: 'https://example.weixin.qq.com/upload', // 仅为示例，非真实的接口地址
        //   filePath: tempFilePaths[0],
        //   name: 'file',
        //   formData: {
        //     user: 'test'
        //   },
        //   success(res) {
        //     const data = res.data
        //     // do something
        //   }
        // })
      }
    })
  },


  //点击提交
  submitAll:function(e){
    //console.log(this)
    var that = this
    var proposerName = that.data.applicantName;
    var proposerNumber = that.data.mobilephoneNumber;
    var theNumberlength = proposerNumber.length;
    var addressPro = that.data.province
    var addressCity = that.data.city
    var addressArea = that.data.area
    var proposerVillage = that.data.villageName;
    var doorplate = that.data.addressNumber;
    var bankName = that.data.bank
    var openbank = that.data.openingBank;
    var bankcard = that.data.bankCard
    if (proposerName == "") {
        wx.showToast({
          title: '请填写申请人姓名',
          duration: 2000,
          icon: "none"
        })
    } else if (proposerNumber == "" || theNumberlength != 11) {
        wx.showToast({
          title: '手机号为空或错误',
          duration: 2000,
          icon: "none"
        })
    } else if (addressPro == "" || addressPro == undefined ) {
      wx.showToast({
        title: '请选择省份',
        duration: 2000,
        icon: "none"
      })
    } else if (addressCity == "" || addressCity == undefined){
      wx.showToast({
        title: '请选择城市',
        duration:2000,
        icon:"none"
      })
    }else if(addressArea ==""||addressArea == undefined){
      wx.showToast({
        title: '请选择区域',
        duration:2000,
        icon:"none"
      })
    } else if (proposerVillage == ""){
      wx.showToast({
        title: '小区名称为空',
        duration:2000,
        icon:"none"
      })
    } else if (doorplate ==""){
      wx.showToast({
        title: '请输入详细的门牌号',
        duration:2000,
        icon:"none"
      })
    }else if(bankName =="" || bankName == undefined){
      wx.showToast({
        title: '请选择银行名称',
        duration:2000,
        icon:"none"
      })
    } else if(openbank ==""){
      wx.showToast({
        title: '请输入开户行名称',
        duration: 2000,
        icon: "none"
      })
    } else if (bankcard ==""){ 
      wx.showToast({
        title: '请输入银行卡号',
        duration:2000,
        icon:"none"
      })
    } 
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    //调用封装的方法，为了方便我直接在页面加载的时候执行这个方法
    call.getData('address/getProvinceList',null,this.provinceList, this.fail); //获取省列表
  },
  provinceList: function (data) { //成功调用省列表请求
    var that = this;
    console.log(data)
    that.setData({
      arrayPro:data.data
    })
    //console.log(this.data.theId)
    // console.log(this.data.proId)
    // var parms = {
    //   provinceID: that.data.proId
    // }
    // call.getData('address/getCityList', parms, this.cityList, this.fail); //获取市列表
  },
  cityList: function (data) { //成功调用市列表请求
    var that = this;
    console.log("市列表：")
    console.log(data)
    that.setData({
      arrayCity: data.data
    })
  },
  areaList: function (data) { //成功调用区列表请求
    var that = this;
    console.log("区列表：")
    console.log(data)
    that.setData({
      array: data.data
    })
  },
  fail: function () {
    console.log("失败")
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})